<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>currentLessonTest</title>
<%@ include file="/common/commonLib.jsp"%>
</head>
<body>
<center>
<button id="addTaskMain">添加任务</button><br>
<button id="updateTaskMain">修改任务</button><br>
<button id="taskMainList">任务列表</button><br>
<button id="addAttachment">添加附件</button><br>
<button id="deleteAttachment">删除附件</button><br>
<button id="assignTaskMain">分配</button><br>
<button id="batchAssignTaskMain">批量分配</button><br>
</center>
</body>
<script>

$(document).ready(function(){
	 $("#addTaskMain").on("click",addTaskMain);  
	 $("#updateTaskMain").on("click",updateTaskMain); 
	 $("#taskMainList").on("click",taskMainList);
	 $("#addAttachment").on("click",addAttachment);
	 $("#deleteAttachment").on("click",deleteAttachment);
	 $("#assignTaskMain").on("click",assignTaskMain);
	 $("#batchAssignTaskMain").on("click",batchAssignTaskMain);
	/*  $("#assistant").on("click",testAssistant); 
	 $("#student").on("click",testStudent); 
	 $("#studentList").on("click",testStudentList); 
	 $("#studentDetail").on("click",testStudentDetail); 
	 $("#searchCourse").on("click",testSearchClassCode);  */
	 
})
var addTaskMain=function(){
	var json={
			courseId:1,
			title:"this is a test",
			type:"TESTINLESSON",
			description:"this is a descprition",
			requirement:"sdfsf",
			attachment:{
				files:[{
					name:"第一张",
					url:"sdf"
				}]
			},
			standardAnswer:"this is answer"
	};
	
	$.post(CONTEXT_PATH + "taskMain/ajaxCreate",{
		data : JSON.stringify(json)
	}, function(data) {
		if (data.status == "success") {
			alert(JSON.stringify(data.data));
		} else {
			alert(data.message);
		}
	});
}

var updateTaskMain=function(){
	var json={
			id:1,
			title:"this is not a test",
			type:"TESTINLESSON",
			description:"2423432434324",
			requirement:"sdfsf",
			standardAnswer:"this is answer"
	};
	
	$.post(CONTEXT_PATH + "taskMain/ajaxUpdate",{
		data : JSON.stringify(json)
	}, function(data) {
		if (data.status == "success") {
			alert(JSON.stringify(data.data));
		} else {
			alert(data.message);
		}
	});
}


var taskMainList=function(){
	var json={
		courseId:1			
	};
	$.get(CONTEXT_PATH + "taskMain/ajaxListData",{
		data : JSON.stringify(json)
	}, function(data) {
		if (data.status == "success") {
			alert(JSON.stringify(data.data));
		} else {
			alert(data.message);
		}
	});
}

var addAttachment=function(){
	var json={
			id:1,
			name:"anwserAttach",
			key:"1234567876543",
			type:2
	};
	
	$.post(CONTEXT_PATH + "taskMain/ajaxAddAttachment",{
		data : JSON.stringify(json)
	}, function(data) {
		if (data.status == "success") {
			alert(JSON.stringify(data.data));
		} else {
			alert(data.message);
		}
	});
}

var deleteAttachment=function(){
	var json={
			id:1,
			key:"1234567876543",
			type:2
	};
	
	$.post(CONTEXT_PATH + "taskMain/ajaxDeleteAttachment",{
		data : JSON.stringify(json)
	}, function(data) {
		if (data.status == "success") {
			alert(JSON.stringify(data.data));
		} else {
			alert(data.message);
		}
	});
}

var assignTaskMain = function(){
	var json={
			taskId:1,
			lessonId:1,
			isAnswerVisible:"YES"
	};
	
	$.post(CONTEXT_PATH + "tmassign/ajaxCreate",{
		data : JSON.stringify(json)
	}, function(data) {
		if (data.status == "success") {
			alert(JSON.stringify(data.data));
		} else {
			alert(data.message);
		}
	});
}
var batchAssignTaskMain=function(){
	var json={
			taskId:1,
			items:[{
			    	   lessonId:1,
						isAnswerVisible:"YES"
					},{
						 lessonId:4,
						isAnswerVisible:"YES"
					}]
	};
	
	$.post(CONTEXT_PATH + "tmassign/ajaxBatchCreate",{
		data : JSON.stringify(json)
	}, function(data) {
		if (data.status == "success") {
			alert(JSON.stringify(data.data));
		} else {
			alert(data.message);
		}
	});
}

</script>
</html>